package org.jmetrix.bus.impl;

import org.jmetrix.bus.Bus;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Konstantin Kuzmin
 * @version $Revision$
 * @since 01.10.11
 */
public class NamedBusFactory {
    private static Map<String, Bus> nameToBus = new HashMap<String, Bus>();
    public static final String DEFAULT_BUS = "JMETRIX_DEFAULT_BUS";

    private NamedBusFactory() {
    }

    public static synchronized Bus getBus(final String name) {
        Bus bus = nameToBus.get(name);
        if (bus == null) {
            bus = new NamedBus(name);
            nameToBus.put(name, bus);
        }
        return bus;
    }

    public static Bus getDefaultBus() {
        return getBus(DEFAULT_BUS);
    }

    static synchronized void removeBus(final String name) {
        nameToBus.remove(name);
    }

}
